<template>
  <div class="address">
    <NavBar title="地址管理"></NavBar>
    <van-row type="flex" justify="center">
      <van-col span="22">
        <van-address-list
          v-model="chosenAddressId"
          :list="addrData"
          default-tag-text="默认"
          @add="onAdd"
          @edit="onEdit"
        />
      </van-col>
    </van-row>
  </div>
</template>

<script>
export default {
  data () {
    return {
      userId: localStorage.getItem('userId'),
      addrData: [],
      chosenAddressId: 1
    }
  },
  created () {
    this.loadDate()
  },
  methods: {
    async loadDate () {
      const { data: res } = await this.$post(this.API.API_URL_CONTECT, {
        userId: this.userId
      })
      this.addrData = res.data
      this.chosenAddressId = this.addrData[0].id
      this.addrData.forEach(item => {
        item.tel = item.mobile
      })
    },
    onAdd () {
      this.$router.push('/address/add')
    },
    onEdit (item, i) {
      this.$router.push('/address/edit/' + this.addrData[i].id)
    }
  }
}
</script>

<style>
</style>
